package com.huangfu.easysardine.admin.config.druid;

import com.alibaba.druid.support.http.WebStatFilter;

import javax.servlet.FilterChain;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.annotation.WebFilter;
import javax.servlet.annotation.WebInitParam;
import java.io.IOException;

/**
 * Created with IntelliJ IDEA.
 * User: huangfu.daohui
 * Date: 2017-8-10
 * Time: 9:17
 * Description:
 *
 * @WebFilter将一个实现了javax.servlet.Filte接口的类定义为过滤器组件 属性filterName声明过滤器的名称, 可选
 * 属性urlPatterns指定要过滤 的URL模式,也可使用属性value来声明.(指定要过滤的URL模式是必选属性)
 * 属性initParams为指定一组过滤器初始化参数，等价于 <init-param> 标签。
 */
@WebFilter(filterName = "druidWebStatFilter", urlPatterns = "/druid/*",
        initParams = {
                @WebInitParam(name = "exclusions", value = "*.js,*.gif,*.jpg,*.bmp,*.png,*.css,*.ico,/druid/*")// 忽略资源
        })
public class DruidStatFilter extends WebStatFilter {

    @Override
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
        response.setContentType("text/html");
        super.doFilter(request, response, chain);
    }
}
